/*
剑指 Offer 58 - I. 翻转单词顺序
解题思路：分割，注意要考虑多个空格的情况
 */
public class Offer58 {

  public static void main(String[] args) {
    System.out.println(Offer58.reverseWords("the sky is  blue"));
  }

  public static String reverseWords(String s) {
    String[] split = s.trim().split(" ");
    StringBuilder res = new StringBuilder();
    for (int i = split.length - 1; i >= 0 ; i--) {
      if (split[i].equals("")){
        continue;
      }else {
        res.append(split[i] + " ");
      }
    }
    return res.toString().trim();
  }
}
